home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pistol.zip / PISTOL.DOC < prev    next >
Text File  |  1987-08-20  |  39KB  |  1,249 lines

  1. *********************************************************
  2. *                            *
  3. * PISTOL-Portably Implemented Stack Oriented Language    *
  4. *            Version 1.3            *
  5. * (C) 1982 by    Ernest E. Bergmann            *
  6. *        Physics, Building #16            *
  7. *        Lehigh Univerisity            *
  8. *        Bethlehem, Pa. 18015            *
  9. *                            *
  10. * Permission is hereby granted for all reproduction and    *
  11. * distribution of this material provided this notice is    *
  12. * is included.                        *
  13. *                            *
  14. *********************************************************
  15.  
  16.       BRIEF, PRELIMINARY DOCUMENTATION ON PISTOL 1.3:
  17.  
  18.         (updated February 24, 1982)
  19.  
  20.     PISTOL is a Portably Implemented Stack Oriented
  21. Language that has been developed for general use and
  22. experimentation. It is at an early developmental stage and so
  23. may have lots of "bugs". I would appreciate any comments and
  24. suggestions.  For the DEC-20, it has been implemented in
  25. PASCAL;  for CP/M, it has been implemented with the BD Software
  26. C compiler v1.4.
  27.  
  28.     PISTOL resembles an HP calculator in many ways.  It
  29. uses a (parameter) stack to pass numbers between routines.  The
  30. language is "RPN", that is Reverse Polish Notation.  At
  31. present, all arithmetic is performed in integer form.  This
  32. language was inspired by and has evolved from two mini- and
  33. micro- based languages, FORTH (Charles Moore, 1970) and STOIC
  34. (MIT and Harvard Biomedical Engineering Center, 1977).
  35.  
  36.  
  37. GETTING STARTED
  38. ======= =======
  39.     Before describing the language further, this is how to
  40. "bring it up":
  41.  
  42. type
  43.     DIR CORE1 to see if this file exists, otherwise, type
  44.     DIR PBASE to make sure this file exists.
  45.  
  46.  
  47. type
  48.     EXE PISTOL.PAS
  49. (and for the DEC-20):
  50. link TTY: to the input.
  51.  
  52.     PISTOL should come up with:
  53.  
  54. ***PISTOL 1.3***
  55. X>
  56.  
  57.     To make it smarter, it can be "educated" with a set of
  58. useful definitions already prepared in a file named, CORE1 or
  59. PBASE ; to do this type:
  60.  
  61. X> 'CORE1 RESTORE    (only if CORE1 exists!)
  62. or
  63. ==
  64.  
  65. X> 'PBASE LOAD        (if PBASE exists; this is much slower)
  66. X> 'CORE1 COREDUMP    (creates CORE1 for future use)
  67.  
  68.  
  69. TUTORIAL:
  70. =========
  71.  
  72.     Before discussing some examples and features, it is
  73. probably best to understand the "prompt".  The prompt is what a
  74. program types at the beginning of the line when it is awaiting
  75. input from the user.  The prompt supplied by PISTOL can be
  76. several characters long and it is to inform or remind the user
  77. about the "state" of the program.  If a number appears at the
  78. beginning of the prompt, it signifies that the parameter stack
  79. is not empty.  Next, a letter is displayed (such as "X") that
  80. indicates the current number base used for i/o ("X", the Roman
  81. numeral for "10", signifies decimal). After this letter there
  82. may be other characters or symbols that are used to indicate if
  83. you are in the middle of some syntactical construction.
  84. Finally, the ">" completes the prompt expression.  In the
  85. examples supplied above and below we have attempted to suggest
  86. the typical prompts that one might expect to see.
  87.  
  88.     After educating PISTOL by loading PBASE or by restoring
  89. CORE1, the system is "smarter" you can try the following
  90. examples:
  91.  
  92. X> 1 2 23 STACK
  93.  
  94. The system takes each number as encountered and places them on
  95. the stack.  The word, STACK , prints the current contents of
  96. the stack without changing the stack in any way.
  97.  
  98.     Now try typing:
  99. 3X> + STACK
  100.  
  101. This should result in the addition of the top two members of
  102. the stack (2 and 23) and placing the result (answer 25) back on
  103. the stack. The word STACK then displays the current contents of
  104. the stack.
  105.  
  106.     Now try typing:
  107. 2X> * stack
  108.  
  109. The top two items of the stack will be multiplied together and
  110. the result left on the stack.  The word, "stack" is interpreted
  111. as STACK, and we see that the only thing in the stack is the
  112. answer 25.
  113.  
  114.     To disable the automatic interpretation of lowercase
  115. as uppercase, type:
  116.  
  117. X> RAISE OFF (or "raise off")
  118.  
  119. and successive lines will be interpreted without conversion of
  120. lowercase to uppercase.  To revert to conversion, type:
  121.  
  122. X> RAISE ON
  123.  
  124.     There are a number of different options that can be
  125. invoked such as ECHO ON and ECHO OFF which control the listing
  126. of files read in by the '<filename> LOAD operation.  One can
  127. use CONSOLE ON and CONSOLE OFF to determine what reaches the
  128. terminal.  An error condion will automatically restore output
  129. to the terminal.  LIST ON and LIST OFF will determine what
  130. output will also be routed to the output list file(of course a
  131. listfile has to be declared first).  This is useful to have a
  132. more permanent record of what happened during a session.  There
  133. is also a SHOWCODE and a NOSHOWCODE which will show the results
  134. of compiling each input line (that is for those who want or
  135. like to know what is going on behind the scenes).
  136.  
  137.     On the DEC-20 (and also in CP/M) one can exit from
  138. PISTOL by using a control-C, but a more "refined" way is to
  139. type the word, BYE, which will return you to the operating
  140. system.
  141.  
  142.     PISTOL can examine the contents of its own (virtual)
  143. memory. The W@ ("fetch") operator is similar in spirit to the
  144. PEEK function in BASIC.  To place the contents of a memory
  145. location on the stack one simply places the address on stack
  146. and then types W@ .  For example, if we want to place the
  147. current value of RADIX, the base used in all I/O number
  148. conversion, we need to find the value stored in the RAM
  149. location at -1 (i.e. what is RAM[-1]?) we can type:
  150.  
  151. X> -1 W@
  152.  
  153. which will place the desired information on stack.  The inverse
  154. operation, which is more dangerous(because a mistake can crash
  155. the program), is to store a new value in the RADIX, hence
  156. change the number base.  The operator, W! ("word store"),
  157. performs this function(for this example we suppose that the
  158. RADIX address is -1, usually, it is not):
  159.  
  160. X> 16 -1 W!
  161.  
  162. would convert PISTOL to converse in hexadecimal.
  163.  
  164.     Of course it is aukward to remember constants, such as
  165. the address of RADIX so we can define such constants by:
  166.  
  167. X> -1 'RADIX CONSTANT
  168.  
  169. After such a CONSTANT definition we can redo the examples that
  170. use W@ and W! by (RADIX is in fact already defined in PBASE):
  171.  
  172. X> RADIX W@
  173. and
  174. X> 16 RADIX W!
  175.  
  176.     As an additional convenience the user can define space
  177. for variables with the word, VARIABLE.  For example, If you
  178. wish to define a variable with the initial value 0 and named
  179. ANSWER, you should type:
  180.  
  181. X> 0 'ANSWER VARIABLE
  182.  
  183. Later, if you wish to perform the PASCAL statement:
  184.  
  185. ANSWER := ANSWER + 1;
  186.  
  187. you would write the PISTOL code:
  188.  
  189. X> ANSWER W@ 1 + ANSWER W!
  190.  
  191. Notice that you MUST choose an initial value in VARIABLE and,
  192. of course, CONSTANT definitions.
  193.  
  194.     Just like the convenience feature of PASCAL,
  195. for which one can use SUCC(ANSWER) to increment ANSWER
  196. by one, there exists an analogous operator (or you can
  197. define your own!):
  198.  
  199. X> ANSWER 1+W!
  200.  
  201.  
  202.     The language has many resources beyond those presented
  203. so far.  Perhaps the most significant is the ability to define
  204. new words or definitions to make the language increasingly
  205. smarter. Try examining the contents of the file, PBASE , to see
  206. how the definitions may be formed.  As a complex example, the
  207. word, = is defined whose function is to take the top item off
  208. of the stack and print its value.  For example, typing:
  209.  
  210. X> 8 8 + =
  211.  
  212. will cause the system to respond with the answer: 16.  Note
  213. that this calculation causes no net change to the stack(it is
  214. the presence of a number before "X>" that indicates the number
  215. of items in the stack at that moment); its contents before the
  216. first "8" was typed is the same as its contents after the
  217. system responds with 16.  Thus the definition of the word = has
  218. increased the convenience of the system for arithmetic
  219. calculations.
  220.  
  221.     The system can and does handle strings.  Suppose you
  222. would like the system to output "HELLO".  Try typing:
  223.  
  224. X> 'HELLO MSG
  225.  
  226. The system will take the 'HELLO as a string to be placed upon
  227. the stack.  The MSG ,"message" takes the top item off of the
  228. stack, assumes it to be a string, and prints it.  The stack
  229. contains the same stuff after MSG is executed as before the
  230. 'HELLO was typed.
  231.  
  232.     Useful I/O words are CR which will output a carriage
  233. return and line feed sequence.  The word SPACE will output a
  234. space. And the word SPACES will pop the top of stack to obtain
  235. the number of spaces to be output.  For example:
  236.  
  237. X> 'HELLO MSG SPACE 'HELLO MSG CR 5 SPACES 'BYE MSG
  238.  
  239. should produce:
  240.  
  241. HELLO HELLO
  242.      BYE
  243.  
  244.  
  245.     Standard output would be most tedious if we could not
  246. create definitions to speed up programming.  Here is a humorous
  247. example:
  248.  
  249. X> 'HELLO : 'HELLO, MSG SPACE 'YOURSELF! CR ;
  250.  
  251. The use of : and ; provide the means to define a new word
  252. "HELLO" Later, you can type:
  253.  
  254. X> HELLO
  255.  
  256. and the system will respond:
  257.  
  258. HELLO, YOURSELF!
  259.  
  260.     Thus we see that the pair of symbols, ":" and ";"
  261. delineate a structure used to make definitions.  The material
  262. in between the two symbols becomes the definition of the word
  263. whose name is the string that was lastly placed on the stack
  264. before the ":".
  265.  
  266.     One can create strings with embedded blanks and tabs up
  267. to 127 characters long by using double quotes to delineate both
  268. ends of the string.  For example, the word, HELLO, defined
  269. above, could have been defined:
  270.  
  271. 'HELLO : "HELLO, YOURSELF!" MSG CR ;
  272.  
  273. Even with RAISE ON, lowercase characters within double
  274. quotation marks will not be converted.
  275.  
  276.     There are other types of structures.  The pair of
  277. words, DO and LOOP permit an iterative structure.  They use the
  278. top two quantities on the stack as limits of iteration.  So:
  279.  
  280. X> nn n DO ... LOOP
  281.  
  282. is equivalent to the PASCAL structure:
  283.  
  284.     FOR  I := n TO (nn-1) DO
  285.         BEGIN ... END;
  286.  
  287. To place the current value of the iteration variable on the
  288. stack one uses the word, "I" .  Here is an example that you can
  289. try:
  290.  
  291. X> 'COUNTING : CR 1 + 1 DO I = SPACE LOOP ;
  292.  
  293. X> 10 COUNTING
  294. and see PISTOL counting to 10.
  295.  
  296.     An alternative terminating word to this structure is
  297. +LOOP.  If one uses in PISTOL:
  298.  
  299.     nn n DO ... m +LOOP
  300. one simulates the BASIC structure:
  301.  
  302. 100 FOR I=n TO (nn-1) STEP m
  303. .
  304. .
  305. .
  306. 200 NEXT I
  307.  
  308.     PISTOL supports a conditional structure of the form:
  309.  
  310.     IF ... ELSE .... THEN
  311.  
  312. When the IF is encountered the top of the stack is used as a
  313. boolean variable; it is considered false if equal to zero and
  314. true otherwise (as in LISP).  If true, the actions "..." that
  315. are bracketed between IF and ELSE are carried out; then program
  316. flow skips to what follows THEN.  Whereas, if the top of the
  317. stack was false, the actions "...." between ELSE and THEN are
  318. carried out instead. The "ELSE ...." portion is optional, in
  319. analogy to PASCAL.
  320.  
  321.     To illustrate, here is an example:
  322.  
  323. X> 'STATE? :
  324. X:> 'TURNED- MSG W@ IF 'ON ELSE 'OFF THEN
  325. 1X:> MSG ;
  326. X>
  327.  
  328. Trying this new word:
  329.  
  330. X> CONSOLE STATE?
  331. we get the response:
  332. TURNED-ON
  333.  
  334. whereas for:
  335.  
  336. X> LIST STATE?
  337. TURNED-OFF
  338.  
  339.     PISTOL supports a number of other structures which are
  340. analogous to the PASCAL structures:
  341.  
  342.         WHILE .. DO ... ;
  343.  
  344.             and
  345.  
  346.         REPEAT ... UNTIL NOT .. ;
  347.  
  348. They are, respectively:
  349.  
  350.         BEGIN .. IF ... REPEAT
  351.  
  352.             and
  353.  
  354.         BEGIN ... .. END
  355.  
  356.     As in most languages, structures may be nested.  In the
  357. interest of user convenience, the prompt will indicate whether
  358. execution is being deferred, pending completion of unfinished
  359. structures.
  360.  
  361.     PISTOL can communicate in a variety of different number
  362. bases, as was alluded to in the section on W@ and W! . Changing
  363. bases has been formalized by a set of defined words provided in
  364. PBASE.  These words are: BINARY(B), OCTAL(Q), DECIMAL(X), and
  365. HEX(H); the parenthesized letter is the corresponding symbol
  366. that appears in the prompt.  Thus, in the examples described
  367. above, the number base was decimal.  Here are a few examples of
  368. the use of other number bases:
  369.  
  370. X> HEX
  371. H> 8 8 + =
  372. 10
  373. H> 11 BINARY =
  374. 10001
  375. B> 2
  376. 2 ?
  377. ***PISTOL 1.3***
  378.  
  379. B>
  380.     Whenever the system responds with ***PISTOL 1.3*** it
  381. has performed an ABORT which resets stacks and prints this
  382. identifying message.
  383.  
  384.     You may "redefine" words, that is to say, the same name
  385. may be used again and again.  Earlier definitions that use the
  386. word will continue to utilize the old meaning; future defini-
  387. tions that reference the redefined word will access the new
  388. meaning.  A warning will be issued when you are redefining.
  389.  
  390.     It is important to keep in mind that when new words are
  391. defined, their names are added to the "string stack" and the
  392. compiled code is added to the "code stack".  If a recent
  393. definition is not satisfactory, or no longer serves a need, you
  394. may wish to "FORGET" it, so that the "string stack" and the
  395. "code stack" are popped of this useless material.  To discard
  396. this definition AND ALL SUBSEQUENT DEFINITIONS, one should
  397. type:
  398.  
  399. X> '<name> FORGET
  400.  
  401.     To obtain the code locations and names of the last ten
  402. definitions, type:
  403.  
  404. X> TOP10
  405.  
  406. To obtain information successively on the ten previous
  407. defintions, type:
  408.  
  409. 1X> NEXT10
  410.  
  411.     A crude, line-oriented editor has been implemented
  412. recently inside PISTOL.  Try it out by typing the following
  413. sequence of commands:
  414.  
  415. X> LI
  416.  
  417. X> 3 LI
  418.  
  419. X> 3 5 LI
  420.  
  421. X> 4 2 LI
  422.  
  423. X> 3 INPUT
  424. 3: MARY HAD
  425. 4: A LITTLE
  426. 5: LAMB.
  427. 6: <cr>
  428.  
  429.  
  430. X> LI
  431.  
  432. X> 3 DELETE
  433.  
  434. X> LI
  435.  
  436.  
  437.  
  438.  
  439. *************************
  440. *            *
  441. *    GLOSSARY    *
  442. *            *
  443. *************************
  444.  
  445. (Assuming that the definitions in PBASE have been compiled):
  446.  
  447. ARITHMETIC OPERATORS:
  448. ========== =========
  449.  
  450. +    Adds the top two items on stack.
  451.  
  452. -    Subtracts the top two items on stack.
  453.  
  454. *    Multiplies the top two items on stack.
  455.  
  456. /    Divides the top of stack into next to top.
  457.  
  458. MOD    Calculates the remainder ("modulo") of division
  459.     of next to top by the top of stack.
  460.  
  461. /MOD    Divides the next to top by the top of stack;
  462.     new next to top is the result and top is the
  463.     remainder.
  464.  
  465. MINUS    Changes the sign of the top of stack.
  466.  
  467. MAX    Leaves the larger of the top two members on stack.
  468.  
  469. MIN    Leaves the smaller of the top two members on stack.
  470.  
  471. ABS    Taks the absolute value of the top of stack.
  472.  
  473. 1+    Increments the top of stack.
  474.  
  475. 1-    Decrements the top of stack.
  476.  
  477. W+    Increments the address on top of stack by the wordsize.
  478.  
  479. 1+W!    Increments the word variable addressed
  480.     by the top of stack.
  481.  
  482. W+W!    Increments address variable addressed by the top of
  483.     stack by the word size.
  484.  
  485. LOGICAL OPERATORS:
  486. ======= =========
  487.  
  488. TRUE    Pushes -1 on stack.
  489.  
  490. FALSE    Pushes 0 on stack.
  491.  
  492. NOT    [A quantity is "false" if zero; otherwise,it is "true"].
  493.     Replaces top of stack by FALSE if non-zero;
  494.     otherwise replaces top by TRUE.
  495.  
  496. LAND    If either of the top two items on stack is zero,
  497.     it pushes FALSE on stack; otherwise it pushes TRUE.
  498.     ("LOGICAL AND").
  499.  
  500. LOR    If both items on stack are zero, it pushes FALSE;
  501.     otherwise it pushes TRUE.  ("LOGICAL OR").
  502.  
  503. GT    Pushes TRUE if the next to top is greater than
  504.     the top of stack.
  505.  
  506. LT    Pushes FALSE if next to top is less than
  507.     the top of  stack.
  508.  
  509. LTZ    Pushes TRUE if top of stack is less than zero;
  510.     otherwise, it pushes FALSE.
  511.  
  512. GTZ    Pushes TRUE if top of stack is greater than zero;
  513.     otherwise, it pushes false.
  514.  
  515. EQZ    Pushes TRUE if the top of stack is zero; otherwise,
  516.     it pushes FALSE.
  517.  
  518. EQ    Pushes TRUE if the top two members on stack were
  519.     equal; otherwise it pushes FALSE.
  520.  
  521. ..    (Takes three arguments).  Tests for range.  The top
  522.     three items pushed on the stack should be value,
  523.     bottom of range, and top of range.  If value is below
  524.     bottom or above top, FALSE is pushed on stack;
  525.     otherwise TRUE is pushed on stack.
  526.  
  527.  
  528. STACK OPERATORS:
  529. ===== =========
  530.  
  531. STACK    Non-destructively lists the size and contents of
  532.     the parameter stack.
  533.  
  534. RSTACK    Non-destructively lists the size and contents of
  535.     the return stack.
  536.  
  537. SWAP    Interchanges the top two items on stack.
  538.  
  539. DUP    Pushes a duplicate copy of the top of stack.
  540.  
  541. DDUP    Pushes a duplicate pair of the top two items.
  542.  
  543. DROP    removes the top item from the stack.
  544.  
  545. OVER    pushes the next to top on top of stack.
  546.  
  547. 2OVER    pushes the second to top on top of stack.
  548.  
  549. 3OVER    pushes the third to top on the stack.
  550.  
  551. S@    Takes the top member of stack as an index to the
  552.     interior of the stack; " 0 S@ " is equivalent
  553.     to " DUP ".
  554.  
  555. R@    Take the top of the parameter stack as an index
  556.     into the return stack.
  557.  
  558. <R    Pushes the top of stack on to the return stack.
  559.  
  560. R>    (opposite of " <R ").
  561.  
  562. SP    pushes the current size of stack on stack.
  563.  
  564. RP    pushes the current size of the return stack.
  565.  
  566. L@    similar to S@ and R@ but for the loop stack.
  567.  
  568. CASE@    similar to S@ and R@ but for the case stack.
  569.  
  570. DEFINITIONAL OPERATORS:
  571. ============ =========
  572.  
  573. CONSTANT    defines a word whose name is on the top    of
  574.         stack and assigns it the permanent value given
  575.         by the next to top.
  576.  
  577. VARIABLE    Allocates space in RAM and defines a word whose
  578.         name is on top of stack.  Later, when the name
  579.         is invoked, a pointer to the allocated space is
  580.         pushed on stack.  The variable is initialized
  581.         to the next to top of stack.
  582.  
  583. :  ... ;    is used in creating a standard definition.
  584.         It takes the string pointed to by the top of
  585.                 stack as the name of the word being defined.
  586.                 The body of the word is anything that is placed
  587.                 between the ":" and the ";". When the
  588.                 definition extends beyond one line of text,
  589.                 thesystem displays a prompt that contains a
  590.                 ":".  Examples have been provided already in
  591.                 the tutorial.
  592.  
  593. $: ... ;$    is used to create a "macro" definition.  In
  594.                 syntax and use its behavior is very similar to
  595.                 a standard definition, as described immediately
  596.                 above.  However the code that is associated
  597.                 with the newly defined word will be compiled
  598.                 "in line" when the word is invoked, instead of
  599.                 being called.  Its use increases the execution
  600.                 speed of any code that uses the word (since the
  601.                 is no overhead from a "call"), but the
  602.                 resulting code is usually longer; thus we can
  603.                 choose our own preference between speed and
  604.                 memory space.  It is used to define "perfect
  605.                 NOPs", such as in the definition of W* when the
  606.                 word size is, in fact, 1. (see the beginning of
  607.                 PBASE).
  608.  
  609. MEMORY RELATED OPERATORS:
  610. ====== ======= =========
  611.  
  612.  
  613. W@    Fetches the contents of the word location addressed
  614.     by the top of stack (used extensively with words
  615.     defined by VARIABLE).
  616.  
  617. W!    Stores at the word location addressed by the top of
  618.     stack the value next to top.
  619.  
  620. W<-    equivalent to " SWAP W! "
  621.  
  622. C@    fetches the ASCII value of the character in the
  623.     string area addressed by the top of stack.
  624.  
  625. C!    stores in the string area addressed by the top of
  626.     stack the character whose ASCII value is next to
  627.     the top.
  628.  
  629. R@ , S@, L@, and CASE@    (see stack operations, above)
  630.  
  631. ON    sets location addressed by top of stack to TRUE.
  632.  
  633. OFF    sets location addressed by top of stack to FALSE.
  634.  
  635.  
  636. SYSTEM OPERATIONS:
  637. ====== ==========
  638.  
  639. COREDUMP    saves an image of PISTOL's memory as a
  640.         file named with the string previously
  641.         placed on top of the stack.  (for an
  642.         example see "GETTING STARTED", near the
  643.         start of this documentation).
  644.  
  645. RESTORE        takes the file whose name is on the top
  646.         of stack and "restores" the memory image
  647.         that had been previously saved by a
  648.         COREDUMP command.  (for an example see
  649.         "GETTING STARTED", near the start of this
  650.         documentation).
  651.  
  652. LISTFILE    opens a new file with the name that was
  653.         on the top of stack.  This new file can
  654.         be written into to keep a record of the
  655.         terminal session (using the boolean:
  656.         LIST).  For example, to record portions 
  657.         of the terminal session in a file named
  658.         "DIALOG":
  659.  
  660.         X> 'DIALOG LISTFILE
  661.         X> LIST ON
  662.             .
  663.             . (recorded)
  664.             .
  665.         X> LIST OFF
  666.             .
  667.             . (not recorded)
  668.             .
  669.         X> LIST ON
  670.             .
  671.             . (recorded)
  672.             .
  673.             etc.
  674.  
  675. LOAD    is used to take a PISTOL source file whose name is
  676.         pointed to by the top of stack.
  677.  
  678. SHOWCODE    makes pistol display the contents of its
  679.                 compile buffer after every compilation.  It is
  680.                 most useful when you are trying to estimate
  681.                 where special patching needs to be done, such
  682.                 as done by ARGPATCH (see the definitions in
  683.                 PBASE for this one!).  To stop showing code you
  684.                 should use:
  685.  
  686. NOSHOWCODE    turns off the SHOWCODE, described immediately
  687.                 above.
  688.  
  689.  
  690. SYSTEM VARIABLES:
  691. ====== =========
  692.  
  693. COLUMN    current column that the console is believed to be
  694.     in.
  695.  
  696. TERMINAL-WIDTH    current declared maximum line length of
  697.         output device (used to automatically
  698.         insert carriage return,line feeds if
  699.         output overruns line).
  700.  
  701. #LINES    contains the number of lines printed since the
  702.     last carriage return was input from the keyboard.
  703.  
  704. TERMINAL-PAGE    current declared maximum number of lines
  705.         user will accept.  Output will pause
  706.         when #LINES equals TERMINAL-PAGE.  Output
  707.         will resume, following a carriage return
  708.         from the keyboard.  Typing a Q followed
  709.         by the carriage return will abort the
  710.         current activity.
  711.  
  712. TAB-SIZE    is the current gap size between tab stops
  713.         (initially set to 8).
  714.  
  715. TRACE-LEVEL    Boolean and number related to level of
  716.         return stack where trace action occurs.
  717.  
  718. TRACE-ADDR    contains patched address for TRACE .
  719.  
  720. RAISE    Boolean that determines whether lowercase input
  721.     is to be converted to uppercase (does not affect
  722.     text between double quotes).
  723.  
  724. ECHO    Boolean controlling display of files being loaded.
  725.  
  726. CONSOLE    Boolean controlling output to console.
  727.  
  728. LIST    Boolean controlling output to the "list" file.
  729.  
  730. CURRENT    contains pointer to the last defined word's definition.
  731.  
  732. .D    contains current end of RAM used to store definitions.
  733.  
  734. .C    contains current end of the compile buffer.
  735.  
  736. RADIX    contains current base for numerical I/O.
  737.  
  738. RADIX-INDICATOR    contains prompt character displaying
  739.         current base.
  740.  
  741. FENCE    contains lower limit for FORGET to prevent
  742.     inadvertent excessive "loss of memory".
  743.  
  744. USER    is a memory constant that is used in calculations to
  745.         locate various system variables and constants.
  746.  
  747. W    is a constant that indicates the separation of word
  748.         addresses.  Different virtual machines may have
  749.         different word sizes and the use of this constant makes
  750.         it possible to transport PISTOL code among such
  751.         different machines.  Its use appears in many
  752.         definitions such as W+ , W- , and W* .
  753.  
  754. VERSION    is the constant, 13. (for PISTOL 1.3)
  755.  
  756.  
  757. I/O OPERATIONS:
  758. === ==========
  759.  
  760. TYI    inputs a character from the keyboard and places
  761.     its ASCII value on the stack.  (Console input is
  762.         buffered line-by-line).
  763.  
  764. TYO    outputs a character whose ASCII value is on the    stack.
  765.  
  766. TYPE    types the number of characters of text specified
  767.     by the top of stack from the string area, starting at
  768.     the location pointed to by the next to top of stack.
  769.  
  770. MSG    types a message pointed to by the top of stack;
  771.     starts a new line if the string is too long to
  772.     "fit" on current line(tabs not properly estimated).
  773.  
  774. MSGS    takes the number on top of stack as the number of
  775.     that are next to the top of stack that are to be
  776.     output, the BOTTOM-MOST one first.  For example:
  777.  
  778.     'ONE 'TWO 'THREE 3 MSGS
  779.  
  780.     produces:
  781.  
  782.     ONETWOTHREE
  783.  
  784.     If the combined length of all the strings will
  785.     not fit on the current line, a new line is started.
  786.     (tabs not properly estimated).
  787.  
  788. TAB    simulates a tab; tab stops are separated by the
  789.     size specified by the variable, TAB-SIZE.
  790.  
  791. TABS    outputs as many simulated tabs as is specified
  792.     by the top of stack.
  793.  
  794. INDENT    advances to the coulumn specified by the top of
  795.     stack unless one is already there or beyond.
  796.     Trying to indent beyond TERMINAL-WIDTH, causes
  797.     a new line to be started instead.
  798.  
  799. ASCII    converts a small number (a digit) into its ASCII
  800.     representation.
  801.  
  802. SPACE    outputs a blank.
  803.  
  804. SPACES    outputs as many blanks as specified by top of stack.
  805.  
  806. CR    Outputs a carriage return, line-feed sequence.
  807.  
  808. IFCR    does a CR if not in column 0.
  809.  
  810. =    type the numerical value of the top of stack;
  811.     no leading or trailing blanks are supplied.
  812.  
  813. ?    types the numerical value of the RAM location
  814.     pointed to by the top of stack; equivalent to
  815.     " W@ = ".
  816.  
  817. HEX    sets the base for numerical I/O to 16.
  818.  
  819. OCTAL    "    "    "    "    "   8.
  820.  
  821. BINARY    "    "    "    "    "   2.
  822.  
  823. DECIMAL    "    "    "    "    "  10.
  824.  
  825.  
  826. %    is the comment delimiter; the compiler ignores
  827.         remaining text to the end of the current line.  Do not
  828.         shun its use in creating PISTOL source files;  PISTOL
  829.         is NOT self documenting!
  830.        ===
  831.  
  832. EDITOR
  833. ======
  834.     (Line numbers change with the editing process, the first
  835. line in the file is numbered 1, the next, 2, etc.)
  836.  
  837. NEWF    resets pointers in the editor so that the edit buffer
  838.     is empty.
  839.  
  840. LISTALL    lists the complete contents in the edit buffer.
  841.  
  842. LFIND    take the line number from the top of stack and replaces
  843.     it with a pointer to the string pointing to the    string
  844.     corresponding to that line.
  845.  
  846. LI    lists portions of the edit buffer; it acts differently
  847.     depending upon the number of arguments on stack.  If
  848.     there are no arguments, everthing is listed (LISTALL).
  849.     If there is a single line number on the stack, that
  850.     single line is displayed.
  851.         Listing a sequence of lines within the edit
  852.     buffer is achieved with two line numbers on the stack.
  853.     The sequence of displayed lines begins with the line
  854.     numbered by the bottom of stack.  If the top of stack
  855.     contains a larger number, that number is the number
  856.     of the last line in the displayed sequence.  Otherwise,
  857.     if it is a smaller number, it is used to specify the
  858.     total number of lines in the sequence.
  859.  
  860. INPUT    takes the line number on the top of stack and allows
  861.     the user to enter (insert above the old line specified)
  862.     as many new lines as desired.  Completion of input is
  863.     signified by supplying an empty line (an immediate
  864.     carriage return).
  865.  
  866. DELETE    takes a single line number and deletes that line from
  867.     the edit buffer.
  868.  
  869. DELETES deletes several lines.  How many is specified by the
  870.     top of stack.  The location by the next to top.
  871.  
  872. OPENR     takes a string pointed to by the top of stack and
  873.     opens that named file for reading.  It is the user's
  874.     responsibility to make sure that the named file
  875.     exists already.  If another file was opened for reading
  876.     previously, it is closed by this new OPENR.
  877.  
  878. OPENW    takes a string pointed to by the top of stack and
  879.     opens that named file for writing.
  880.     (*** It will DESTROY any file that already exists
  881.     with that name!!!****)
  882.  
  883. READLINE reads a line of text from the file that has been
  884.         opened for reading (from OPENR) and places it into
  885.         the input line buffer, pointed to by LINEBUF. This
  886.     text will be overwritten by the next input line so
  887.     it should be used prior to the next input line.
  888.  
  889. WRITELINE writes that line that is in STRINGS (usually in
  890.     the edit buffer) whose pointer is on the top of the
  891.     stack.  The writing is into the file that was opened
  892.     for writing by OPENW.
  893.  
  894. READ    takes the number of lines specified by the top of
  895.     stack from the file specified by the last OPENR and
  896.     appends them to the end of text in the edit buffer.
  897.  
  898. WRITE    takes the number of lines specified by the top of
  899.     stack from the beginning of the text in the edit
  900.     buffer and places them at the end of the file
  901.     specified in the last OPENW.
  902.  
  903. FINISH    is used to end the edit session.  It appends both
  904.     the contents of the editbuffer to the file
  905.     specified in the last OPENW and the remaining
  906.     lines of the file specified by the last OPENR.
  907.  
  908.  
  909. ITERATION
  910. =========
  911.  
  912.     PISTOL provides four means for iterative execution
  913. of a sequence of words, namely:
  914.  
  915. BEGIN ... END
  916.  
  917.     executes words between BEGIN and END until a
  918. condition is satisfied.
  919.  
  920. BEGIN ... IF ... REPEAT
  921.  
  922.     is similar to BEGIN ... END except the condition is
  923. tested at the beginning of the loop; iteration terminates
  924. when the tested condition is false.
  925.  
  926. DO ... LOOP
  927.  
  928.     executes the words between DO and LOOP, running an
  929. index [accessible as "I"] from a lower to upper limit,
  930. incrementing by one each time.
  931.  
  932. DO ... n +LOOP
  933.  
  934.     executes the words between DO and +LOOP, running
  935. an index from a lower to an upper limit, incrementing 
  936. by n each time.
  937.  
  938.     Iterations may be nested subject to the normal
  939. restrictions on overlapping ranges, i.e. any iteration which
  940. is initiated within the range of another iteration must be
  941. terminated within that same range.  PISTOL has implemented a
  942. "check stack" to enforce this syntax rule and, as an aid to
  943. interactive programming, displays this stack in the prompt.
  944.  
  945.     We shall describe these four iterative structures in
  946. more detail now:
  947.  
  948. BEGIN ... END
  949. =============
  950.     The BEGIN ... END syntax permits the user to execute
  951. a sequence of words and then, depending upon a computed
  952. logical variable, either loop back or continue on:
  953.  
  954. BEGIN word1 word2 .... wordm END
  955.  
  956.     The sequence word1, word2, ... is executed once.
  957. When END is reached, the top of the stack is popped and
  958. tested.  If it is true (non-zero) then control passes to the
  959. word following END.  If it is false (zero) then control
  960. passes back to the word following BEGIN.
  961.  
  962. An example:
  963.  
  964.     'EXAMPLE : BEGIN 1- DUP DUP = EQZ END DROP ;
  965.  
  966.     defines the word EXAMPLE which might be called
  967.     as follows:
  968.  
  969.     X>  5 EXAMPLE
  970.     4 3 2 1 0
  971.  
  972.     Each time through the loop, the top of the stack
  973.     (initially the number 5) is decremented, printed and
  974.     compared to zero.  If it is not zero, the loop is
  975.     repeated; the loop terminates when it becomes zero.
  976.  
  977. BEGIN ... IF ... REPEAT
  978. =======================
  979.     BEGIN ... IF ... REPEAT is similar to BEGIN ... END
  980. except that the test is at the beginning of the loop.  The
  981. words between BEGIN and IF are executed. The top of the
  982. stack is then popped and tested.  If it is true (non-zero)
  983. the words between IF and REPEAT are executed and control
  984. passes back to the first word after BEGIN. If the top of the
  985. stack had been tested false (zero) control would have passed
  986. to the word following REPEAT.
  987.  
  988. An example:
  989.  
  990.     'LENGTH : 0 BEGIN SWAP DUP IF W@ SWAP 1+ REPEAT UNDER ;
  991.  
  992.     might be used to determine the length of a chain of
  993.     pointers terminated by zero.  The initial pointer
  994.     would be placed on the stack and LENGTH would be
  995.     invoked.  If one could not place the test at the
  996.     beginning of the iteration, one would have a problem
  997.     with a zero length chain (a zero initially on the
  998.      stack).
  999.  
  1000.  
  1001. DO LOOPS
  1002. ========
  1003.     A DO LOOP facility is provided by PISTOL for indexing
  1004. through a sequence of words.  There are two forms of DO LOOP:
  1005.  
  1006. HIGH LOW DO word1 word2 ... wordn LOOP
  1007.  
  1008. HIGH LOW DO word1 word2 ... wordn STEP +LOOP
  1009.  
  1010.     The limits HIGH and LOW (the top two stack entries) are
  1011. compared.  If HIGH is less than or equal to LOW, control passes
  1012. to the word following LOOP or +LOOP.  Otherwise, the sequence
  1013. word1, word2, ... is executed.  LOOP causes the lower limit,
  1014. LOW to be incremented and compared to the upper limit, HIGH.
  1015. If LOW is greater than or equal to HIGH, the loop is
  1016. terminated.  Otherwise another iteration is performed. The
  1017. +LOOP is identical to LOOP except that the LOW is incremented
  1018. by the word on top of stack, STEP. Normally, STEP would be a
  1019. positive number.
  1020.  
  1021.     Within the range of a loop, the current value of the
  1022. loop index is available by using "I".  If DO LOOPs are nested,
  1023. I contains always the value of the innermost index.  The next
  1024. outer indices are available using the words, J and K.  The word
  1025. I' is used to obtain the value of (HIGH+LOW-I-1).  This is used
  1026. to run an index backwards from HIGH-1 to LOW .  The words J'
  1027. and K' are similarly defined.  When parenthesis (iteration
  1028. brackets) are nested with DO LOOPs, they count as one level of
  1029. indexing.  When I is used within the range of an iteration
  1030. bracket the current iteration count (which runs from its
  1031. initial value downwards to one) is placed on stack.
  1032.  
  1033.     The word EXIT causes the innermost loop in which
  1034. it is embedded to terminate unconditionally.
  1035.  
  1036. Some examples:
  1037.  
  1038.     5 0 DO I = LOOP
  1039.  
  1040.     causes the numbers 0 to 4, inclusive to be typed out.
  1041.  
  1042.     5 0 DO 5 0 DO J 5 * I + = LOOP CR LOOP
  1043.  
  1044.     causes the numbers 0 through 24 inclusive to be
  1045.     typed out as 5 lines of 5 numbers each.
  1046.  
  1047.     5 0 DO I' = LOOP
  1048.  
  1049.     causes the numbers 4 ... 0, inclusive to be output.
  1050.  
  1051.     0 21 1 DO I + DUP = 2 +LOOP DROP
  1052.  
  1053.     types out the first 10 perfect squares starting with 1.
  1054.  
  1055.     When using I' (or J' or K') in conjunction with +LOOP,
  1056. HIGH should be replaced by HIGH - STEP + 1  if it is desired
  1057. to produce the same set of indices as with I .  For example:
  1058.  
  1059.     X>  24 0  DO I = 4 +LOOP
  1060.     0 4 8 12 16 20
  1061.  
  1062.     X>  24 0 DO I' = 4 +LOOP
  1063.     23 19 15 11 7 3 1
  1064.  
  1065.     X>  24 4 - 1+ 0 DO I' = 4 +LOOP
  1066.     20 16 12 8 4 0
  1067.  
  1068.  
  1069.  
  1070. CONDITIONALS
  1071. ============
  1072.  
  1073.     PISTOL has a powerful IF ... ELSE ... THEN construction
  1074. which allows moderately complex logical tests to be performed.
  1075. In addition, for more complex situations an OFCASE ... ENDCASE
  1076. n-branch construction is provided also [the"CASE"construction].
  1077. Conditionals may be nested within each other and within
  1078. iteration loops with the same restrictions that apply to
  1079. iterations.  The check check enforces that proper nesting is
  1080. maintained and will issue fatal error messages otherwise.  The
  1081. prompt provides the user with information on the current
  1082. nesting status.
  1083.  
  1084.     For purposes of the conditional, "true" is considered
  1085. to be any non-zero value; "false" is any zero value. [The
  1086. "best" true value is -1, viz. all 1's in binary, in that
  1087. "-1 N AND" will be always "true" unless N is "false".]
  1088.  
  1089. val IF true1 true2 ... ELSE false1 false2 ... THEN
  1090.  
  1091.     The top of stack, val is tested and
  1092.  
  1093.     if true (non-zero), the words true1,true2,...
  1094.     are executed; control passes then to the word
  1095.     following THEN,
  1096.  
  1097.     otherwise, if false (zero) control passes to false1 ,
  1098.     false2 ... ; control passes then to the word
  1099.     following THEN, 
  1100.  
  1101. Two examples:
  1102.  
  1103.     'ABS : DUP LTZ IF MINUS THEN ;
  1104.  
  1105.     defines the word ABS which replaces the top of stack
  1106.     with its absolute value.
  1107.  
  1108.     'MAX : DDUP GT IF DROP ELSE UNDER THEN ;
  1109.  
  1110.     defines the word MAX which compares the top two stack
  1111.     entries and leaves the larger of the two.
  1112.  
  1113.     The CASE construction simplifies many programs where
  1114. the value of a variable is used to choose among many
  1115. possibilities. Its syntax is necessarily more complex:
  1116.  
  1117. value    OFCASE    <test1> C: <action1> ;C
  1118.         <test2> C: <action2> ;C
  1119.         .    .    .    .
  1120.         .    .    .    .
  1121.         <testn> C: <actionn> ;C
  1122.     ENDCASE
  1123.  
  1124.     The liberal use of carriage returns and tabs in the
  1125. coding improves readability, but is not required by the syntax.
  1126. OFCASE saves value and replaces it on the stack before each
  1127. test. If <test1> is true then <action1> (which may be any
  1128. number of words) is carried out and control skips to the first
  1129. word after ENDCASE. Otherwise, if <test1> is false, value is
  1130. again placed on stack and <test2> performed;  if it proves true
  1131. then <action2> is done and control passes to the word following
  1132. ENDCASE, etc. Thus the first successful test selects the action
  1133. performed.
  1134.  
  1135.     If every test, including <testn> is false, control
  1136. reaches ENDCASE and a fatal error message is generated.
  1137. An example should clarify this (notice how the prompt changes):
  1138.  
  1139. X> 'SPELL : OFCASE
  1140. X:C> 0 EQ C: 'ZERO ;C
  1141. X:C> 1 EQ C: 'ONE ;C
  1142. X:C> 2 EQ C: 'TWO ;C
  1143. X:C> 2 GT C: 'MANY ;C
  1144. X:C> ENDCASE MSG ;
  1145.  
  1146. When testing this definition one finds:
  1147.  
  1148. X> 2 SPELL
  1149. TWO
  1150. X> 3 SPELL
  1151. MANY
  1152. X> -1 SPELL
  1153. CASE EXECUTION ERROR AT 11672 FOR THE VALUE -1       PISTOL
  1154.  
  1155.     The fatal error message provides the address of ENDCASE
  1156. and the value that created the problem.
  1157.  
  1158.     OFCASE does not use the loop stack but uses its own
  1159. "CASE" stack;  the words I , J , K , I' , J' , K' and EXIT will
  1160. properly access the DO...LOOP counters when intermixed with
  1161. this structure. The words, ICASE and JCASE, access the case
  1162. variable of the innermost OFCASE structure and the next to
  1163. innermost OFCASE structure, respectively.  They are somewhat
  1164. analogous to the words I and J of the DO LOOP structure.
  1165.  
  1166.  
  1167. RECURSION
  1168. =========
  1169.     Normally, a procedure cannot invoke itself because it
  1170. is compiled before its own name is recorded;  therefore the
  1171. word RECURSE is provided as a "stand-in" for the name of the
  1172. procedure being defined.  This word also provides the means for
  1173. recursing within the compile buffer, itself.
  1174.  
  1175.     For recursion which requires forward references one has
  1176. to make an extra effort (as one does in PASCAL, which requires
  1177. the use of the reserved word, FORWARD). In PISTOL we must
  1178. define first a variable, say, FW, which is destined to contain
  1179. the address of the forward reference.  One defines then those
  1180. routines that invoke the forward-referenced routine with the
  1181. code:
  1182.  
  1183.     ... FW W@ EXEC ...
  1184.  
  1185. Eventually, one is in the position to define the routine that
  1186. is needed to complete the recursive circle, say, LAST.  After
  1187. defining LAST the recursive loop is established with:
  1188.  
  1189.     'LAST ADDRESS FW W!
  1190.  
  1191. which records the address of LAST in the variable, FW .
  1192.  
  1193.  
  1194. MISCELLANEOUS AIDS
  1195. ============= ====
  1196.  
  1197.     To name the ten most recent definitions one should
  1198. type:  TOP10 .  It will display the information and leave on
  1199. stack the address of the 11th most recent definition.  To name
  1200. further definitions, one can type NEXT10 which takes the
  1201. address off of the stack and names the next ten definitions.
  1202. In turn, it leaves the address of the 21th most recent
  1203. definition on stack.
  1204.  
  1205.     One can dis-assemble a definition using the word, DIS .
  1206. For example:
  1207.  
  1208. X> 'TOP10 DIS
  1209.  
  1210. produces the result:
  1211.  
  1212. 'TOP10 : CURRENT W@ NEXT10 ;
  1213.  
  1214. Not all definitions are disassembled so faithfully.
  1215.  
  1216.     To examine the stack in a non-destructive manner, one
  1217. can use the word, STACK.  It will display the number of items
  1218. in the stack and their values.  For testing definitions it is
  1219. useful to check the stack before and after the definition has
  1220. been invoked.
  1221.  
  1222.     If the definition appears to be faulty, it is often
  1223. useful to debug it by tracing the program flow through the
  1224. definition and the state of the stack at intermediate steps.
  1225. This can be accomplished automatically by the use of the word,
  1226. TRACE.  For example, to trace the action of DDUP one can type:
  1227.  
  1228. X> 1 2 'DDUP TRACE
  1229.  
  1230.  
  1231.     To examine the contents of the return stack in a
  1232. non-destructive manner, one can use the word, RSTACK .
  1233.  
  1234.  
  1235. SHOWCODE and
  1236. NOSHOWCODE    permit you to see (and to stop seeing!) the
  1237.                 generated code in the compile buffer after each
  1238.                 compilation.  It can be educational as well as
  1239.                 important for certain debugging tasks.
  1240.  
  1241.  
  1242. 'name LISTFILE
  1243. LIST ON
  1244. .
  1245. .
  1246. LIST OFF    permit recording details of the session in a
  1247.                 file for later review.  It can be a lot more
  1248.                 convenient then using the printer all the time.
  1249. or testing